package middleware

import (
	"leeframe/internal/pkg/http"
	"strconv"

	"github.com/gin-gonic/gin"
)

// HeaderInfo
// @Description: 校验工作台header中的信息
func HeaderInfo() gin.HandlerFunc {
	return func(c *gin.Context) {
		var (
			appGin = http.Gin{C: c}
		)

		_, err := strconv.ParseInt(c.GetHeader("X-Service-Type"), 10, 64)
		if err != nil {
			appGin.Response(http.InvalidParams, "failed to get X-Service-Type from Request Header", nil)
			c.Abort()
			return

		}

		username := c.GetHeader("X-User-Name")
		if username == "" {
			appGin.Response(http.InvalidParams, "failed to get X-User-Name from Request Header ", nil)
			c.Abort()
			return
		}

		c.Next()
	}
}
